import functools


class Solution(object):
    def minDays(self, n):
        @functools.cache
        def dfs(m):
            if m == 0:
                return 0
            if m == 1:
                return 1
            else:
                min_val = float('inf')
                if m % 2 == 0:
                    min_val = min(min_val, 1 + dfs(m // 2))
                else:
                    min_val = min(min_val, 2 + dfs((m - 1) // 2))
                if m % 3 == 0:
                    min_val = min(min_val, 1 + dfs(m // 3))
                else:
                    if m % 3 == 1:
                        min_val = min(min_val, 2 + dfs((m - 1) // 3))
                    else:
                        min_val = min(min_val, 3 + dfs((m - 2) // 3))
                return min_val

        return dfs(n)

data = Solution()
n = 10
print(data.minDays(n))
